#ifndef THREAD_HPP_
#define THREAD_HPP_

#include <Bust/Utilities.hpp>
#include <stdexcept>

#define BUST_THREAD public bust::Thread

namespace bust {

/**
 * @interface Thread
 * Interface for thread programming in POSIX and WinAPI
 */
class Thread : public bust::noncopyable {
	private:
		friend class ThreadPrivateActions;
		void* _data;
		static bool _isInitialized;
	protected:
		/**
		 * Function what will be run as thread
		 */
		virtual void run() = 0;
	public:
		Thread(); ///< Constructor
		virtual ~Thread(); ///< Destructor
		void init(); ///< Initializer

		/**
		 * Start thread
		 * @return Return 0 if success else return error code
		 */
		bool start();
		/**
		 * Cancel thread
		 * @return
		 */
		virtual bool cancel();
		/**
		 * Join thread
		 * @return
		 */
		bool join();

		bool isRunning();
		bool isCanceled();

		/**
		 * Forces the running thread to relinquish the processor until
		 * 	it again becomes the head of its thread list
		 * @return Returns true if it completes successfully,
		 * 	or it returns a value of false and sets errno to indicate the error.
		 */
		static bool yield();
};

}

#endif /* THREAD_HPP_ */
